import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '@/views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
    meta: {
      title: 'IT作业管理平台',
    }
  },
  {
    path: '/message',
    name: 'Message',
    component: () => import('@/views/Message/index'),
    meta: {
      title: '消息',
    }
  },
  {
    path: '/service',
    name: 'Service',
    component: () => import('@/views/Service/index'),
    meta: {
      title: '服务单'
    }
  },
  {
    path: '/ol',
    name: 'Ol',
    component: () => import('@/views/Ol'),
    meta: {
      title: '报工',
    }
  },
  {
    path: '/declaration',
    name: 'Declaration',
    component: () => import('@/views/Declaration'),
    meta: {
      title: '报表',
    }
  },
  {
    path: '/search',
    name: 'Search',
    component: () => import('@/views/Search'),
    meta: {
      title: '搜索',
    }
  },
  // 消息列表
  {
    path: '/message/list',
    name: 'MessageList',
    component: () => import('@/views/Message/list'),
    meta: {
      title: '消息',
    }
  },
  {
    path: '/message/detail',
    name: 'MessaageDetail',
    component: () => import('@/views/Message/detail'),
    meta: {
      title: '消息详情',
    }
  },
  {
    path: '/ol/detail',
    name: 'OlDetail',
    component: () => import('@/views/Ol/detail'),
    meta: {
      title: '报工'
    }
  },
  // 报工审批
  {
    path: '/ol/audit',
    name: 'OlAudit',
    component: () => import('@/views/Ol/audit'),
    meta: {
      title: '报工'
    }
  },
  // 服务单详情
  {
    path: '/service/detail',
    name: 'ServiceDetail',
    component: () => import('@/views/Service/detail'),
    meta: {
      title: '服务单详情'
      
    }
  },
  // 不同状态服务单列表
  {
    path: '/service/serviceType',
    name: 'ServiceDetail',
    component: () => import('@/views/Service/serviceType'),
    meta: {
      title: 'IT服务单列表'
      
    }
  },
  // 服务单需求操作
  {
    path: '/service/demand',
    name: 'ServiceDemand',
    component: () => import('@/views/Service/demand'),
    meta: {
      title: '需求分解'
    }
  },
  // 设置牵头
  {
    path: '/service/lead',
    name: 'ServiceDemand',
    component: () => import('@/views/Service/lead'),
    meta: {
      title: '设置牵头'
    }
  },
  // 设置牵头
  {
    path: '/service/node-flow',
    name: 'ServiceDemand',
    component: () => import('@/views/Service/node-flow'),
    meta: {
      title: '节点流转'
    }
  },
  // 审批记录
  {
    path: '/service/approvalRecord',
    name: 'ServiceDemand',
    component: () => import('@/views/Service/approvalRecord'),
    meta: {
      title: '审批记录'
    }
  },
  // OA流程
  {
    path: '/service/oaFlow',
    name: 'ServiceDemand',
    component: () => import('@/views/Service/oaFlow'),
    meta: {
      title: 'OA流程'
    }
  },
  // 工作量评估
  {
    path: '/service/workload',
    name: 'ServiceWorkload',
    component: () => import('@/views/Service/workload'),
    meta: {
      title: '工作量评估'
    }
  },
  // 预计人月
  {
    path: '/service/expected',
    name: 'ServiceExpected',
    component: () => import('@/views/Service/expected'),
    meta: {
      title: '预计人月'
    }
  },
  // 添加功能
  {
    path: '/service/features',
    name: 'ServiceFeatures',
    component: () => import('@/views/Service/features'),
    meta: {
      title: '添加功能'
    }
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/Login'),
    meta: {
      title: '登录',
    }
  },
  {
    path: '*',
    redirect: { name: 'Home' }
  }
]

const router = new VueRouter({
  mode: 'history',
  base: '/',
  routes
})

// 修改title
router.beforeEach((to, from, next) => {
  document.title = to.meta.title
  next()
})

export default router
